package com.demo.gateway.orderservice.controller;

import com.demo.gateway.api.user.IUserService;
import com.demo.gateway.orderservice.service.UserService;
import com.demo.gateway.user.entity.User;
import com.demo.gateway.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/order")
public class OrderController {
    @Value("${server.port}")
    String port;

    @Autowired
    IUserService userService;

    @Autowired
    UserService userService2;

    /**
     * 获取用户服务的端口
     * @return
     */
    @GetMapping("/getOrderPort")
    public String getUserPort() {
        return "order-service port：" + port;
    }

    /**
     * 获取用户服务的端口
     * @return
     */
    @GetMapping("/getUser2")
    public Result<List<User>> getUser2() {
        return Result.success(userService2.get2());
    }

    /**
     * 获取用户服务的端口
     * @return
     */
    @GetMapping("/getById")
    public Result<User> getById(@RequestParam String id) {
        return Result.success(userService2.queryById(id));
    }

    /**
     * 获取订单服务的端口
     * @return
     */
    @GetMapping("/getUserPort")
    public String getOrderPort() {
        return "order: user-service port：" + userService.getPort();
    }
}
